<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jun 25, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

class HtmlControl extends Object {
	
	/**
	 * The input name of this control
	 *
	 * @var string
	 */
	var $_inputName = null;
	
	/**
	 * Value of this component
	 *
	 * @var string
	 */
	var $_value = null;
	
	/**
	 * Construtor
	 *
	 * @param string $inputName
	 * @param string/array/object $valueOrArrayContain if array normaly it should be: $_GET, $_POST, $_REQUEST
	 * @return HtmlControl
	 */
	function __construct($inputName, $valueOrArrayContain = null) {
		$this->_inputName = $inputName;
		$this->setValue ( $valueOrArrayContain );
	}
	
	/**
	 * Set value for this
	 *
	 * @param string/array $valueOrArrayContain
	 */
	function setValue($valueOrArrayContain) {
		$val = RubikHelper::getValueFrom ( $valueOrArrayContain, $this->_inputName );
		$this->_value = $val;
	}
	function setFieldHtmlInfo($fieldName, $fieldInfo) {
		$this->_arrayFields[$fieldName] = $fieldInfo;
	}
	/**
	 * Get the inputname of control
	 *
	 * @return string
	 */
	function getInputName() {
		return $this->_inputName;
	}
	
	/**
	 * set the inputname of control
	 *
	 * @param string $inputName
	 */
	function setInputName($inputName) {
		$this->_inputName = $inputName;
	}
	
	/**
	 * Create the HTML text for this control
	 *
	 * @param string $type input type: "text", "radio", "hidden",...
	 * @param string $extAttributes extend attributes of generated control
	 * @param string $id HTML id of this control
	 * 
	 * @return string HTML string
	 */
	function createInputHtml($type, $extAttributes = "", $id = null) {
		if ($id === null) {
			$id = $this->_inputName;
		}
		if (! empty ( $id )) {
			$id = "id=\"$id\"";
		}
		$result = "<input type=\"$type\" name=\"{$this->_inputName}\" value=\"{$this->_value}\" $id $extAttributes />";
		return $result;
	}
	
	/**
	 * Create the hidden HTML text for this control
	 *
	 * @param string $extAttributes extend attributes of generated control
	 * @param string $id HTML id of this control
	 * 
	 * @return string HTML string
	 */
	function createHiddenHtml($extAttributes = "", $id = null) {
		return $this->createInputHtml ( "hidden", $extAttributes, $id );
	}
}
?>